﻿@using System.ComponentModel.DataAnnotations
@using FluentValidation;

<MForm Model="_model" EnableValidation EnableI18n OnValidSubmit="HandleOnValidSubmit"
       OnInvalidSubmit="HandleOnInvalidSubmit">
    <MTextField @bind-Value="_model.Name"
                Counter="10"
                Label="Name"></MTextField>
    <MTextField @bind-Value="_model.Email"
                Label="E-mail"></MTextField>
    <MSelect @bind-Value="_model.Item"
             Items="@_items"
             Label="Item"
             ItemText="u => u"
             ItemValue="u => u"></MSelect>
    <MCheckbox @bind-Value="_model.Agree"
               Label="Do you agree?"></MCheckbox>
    <MButton Type="submit">Submit</MButton>
</MForm>

@code {
    class Model
    {
        [Required]
        [MaxLength(10, ErrorMessage = "Name must be at most 10 characters long.")]
        public string Name { get; set; }
        [Required]
        [EmailAddress]
        public string Email { get; set; }
        [Required]
        public string Item { get; set; }
        [RegularExpression("True", ErrorMessage = "You must agree to continue!")]
        public bool Agree { get; set; }
    }

    private bool _valid = true;
    private MForm _form;
    private Model _model = new();

    List<string> _items = new()
    {
        "Item 1",
        "Item 2",
        "Item 3",
        "Item 4"
    };

    private void HandleOnValidSubmit()
    {
        //valid
    }

    private void HandleOnInvalidSubmit()
    {
        //invalid
    }
}
